package com.shop.shopserver.mapper;

import com.shop.shoppojo.dto.AddressDTO;
import com.shop.shoppojo.entity.Address;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * 地址Mapper
 */

@Mapper
public interface AddressMapper {
    /**
     * 新增地址
     * @param addressDTO
     */
    @Insert("insert into address" +
            "        (addressDetail, areaCode, city, country, county, isDefault, name, postalCode," +
            "         province, tel,user_id)" +
            "        values (#{addressDetail}, #{areaCode}, #{city}, #{country}, #{county}, #{isDefault}, #{name}, #{postalCode}," +
            "                #{province}, #{tel},#{userId})")
    void insert(AddressDTO addressDTO);

    /**
     * 更新地址
     * @param addressDTO
     */
    void update(AddressDTO addressDTO);

    /**
     * 获取地址
     * @return
     */
    List<Address> list(Address address);


    /**
     * 删除地址
     * @param id
     */

    @Delete("delete from address where id = #{id}")
    void deleteById(Long id);


    /**
     * 根据 用户id修改 是否默认地址
     * @param addressDTO
     */
    @Update("update address set isDefault = #{isDefault} where user_id = #{userId}")
    void updateIsDefaultByUserId(AddressDTO addressDTO);






}
